<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" import="java.util.*,com.epam.tcs.actions.*,com.epam.tcs.dao.hibernate.entities.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ include file="../template/header.jsp" %>
<%@ include file="../template/left_menu_alt.jsp" %>
<div id="content">
	<div id="breadcrumbs">
		<c:if test="${requestScope.breadcrumbs != null}">
			<c:set var="i" value="0"/>
			<c:forEach items="${requestScope.breadcrumbs}" var="bc">
				<a href="${pageContext.request.contextPath}${bc.getUrl()}">${bc.getCaption()}</a>		
			</c:forEach>
		</c:if>
	</div>
	<span style="color: green;">
		${requestScope.message}
	</span>
	<c:if test="${sessionScope.listLectures != null}" >
	<form name="lecture_form" method=post action="">
	<table>	
		<tr>
			<th><input type="checkbox" onclick="checkAll()" name="lecture_check"/></th>
			<th></th>
			<th>Название</th>
			<th>Тема</th>	
			<th>Описание</th>
		</tr>
		<c:forEach items="${sessionScope.listLectures}" var="lecture" >		
			<tr>
				<td><input type="checkbox" name="lecture_check_${lecture.lecPracId}"/></td>
				<td><a href="${pageContext.request.contextPath}/tcs/lecture/edit?lecture_id=${lecture.lecPracId}"><span class="ui-icon ui-icon-pencil"></span></a></td>
				<td>${lecture.name}</td>
				<td>${lecture.theme.name}</td>				
				<td>${lecture.description}</td>
			</tr>
		</c:forEach>
	</table>
	</form>
	</c:if>
</div>
<script type="text/javascript">
$(function() {
	$('#del_lecture').bind('click', function(){
		deleteLectures();
	});
	$('#add_lecture').bind('click', function(){
		addLecture();
	});
});
function addLecture() {
	window.location = "${pageContext.request.contextPath}/tcs/lecture/add";
}
function checkAll() {
	if ($("input[name = lecture_check]").attr("checked")) {
		$("input[name ^= lecture_check]").each(
			function() {
				$(this).attr("checked",true);
			}
		);
	} else {
		$("input[name ^= lecture_check]").each(
				function() {
					$(this).attr("checked",false);
				}
			);
	}
}
function deleteLectures() {
	var lectures = [];
	$("input[name ^= lecture_check]:checked").each(
		function(index) {
			lectures[index] = $(this).attr("name");
		}
	);
	$("form[name = lecture_form]").attr("action", "${pageContext.request.contextPath}/tcs/lecture/del");
	$("form[name = lecture_form]").submit();	
}
</script>
<%@ include file="../template/footer.jsp" %>